﻿<div class="form-horizontal" ms-controller="JFBXADD">
    <div class="form-group">
        <label class="col-xs-2 control-label">表单申请人</label>
        <div class="col-xs-4">
            <p class="form-control-static" ms-text="modelData.ShenQingRen"></p>
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">报销时间</label>
        <div class="col-xs-4">
            <input type="text" ms-duplex="modelData.BXDate" class="form-control szhl_form_date  szhl_require">
        </div>
    </div>
    <div class="form-group hide">
        <label class="col-xs-2 control-label"><span class="Required">*</span>审核人</label>
        <div class="col-xs-4">
            <select class="form-control">
                <option value="admin">管理员</option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">消费记录</label>
        <div class="col-xs-9">
            <table class="table table-bordered table-hover table-hover table-striped">
                <thead>
                    <tr><th>消费类别</th><th>金额</th><th>时间</th><th>事由</th><th>操作</th></tr>
                </thead>
                <tbody>
                    <tr ms-repeat-item="JFBXItemList">
                        <td>{{item.LeiBie}}</td>
                        <td>{{item.BXJE}}</td>
                        <td>{{item.BXDate|date("yyyy-MM-dd")}}</td>
                        <td>{{item.BXContent}}</td>
                        <td><button class="btn btn-danger  btn-xs" style="margin-left:10px" ms-click="DelItem(item)"> <i class="fa fa-edit"></i>删除</button></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label"><span class="Required">*</span>总金额（元）</label>
        <div class="col-xs-4">
            <input type="text" class="form-control  szhl_require" ms-duplex="modelData.BXZJE" id="inputEmail3">
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">描述</label>
        <div class="col-xs-9">
            <textarea id="conContent" class="span2  form-control" ms-duplex="modelData.BXContent"></textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">抄送人</label>
        <div class="col-xs-9">
            <input type="text" class="form-control szhl_getPeoples" ms-duplex="modelData.ChaoSongRen" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">附件</label>
        <div class="col-xs-9">
            <input type="text" value="" class="span2  szhl_Upload form-control" ms-duplex="modelData.Files" />
        </div>
    </div>

</div>
<script>

    var strId = ComFunJS.getQueryString("ID");
    var ItemId = ComFunJS.getQueryString("Ids");
    var model = avalon.define({
        $id: "JFBXADD",
        JFBXItemList: [],
        modelData: { "ShenQingRen": ComFunJS.convertuser(ComFunJS.getCookie('username')), "BXDate": "", "BXZJE": "", "BXContent": "", "ChaoSongRen": "", "Files": "", "ChaoSongRen": "", "ItemIds": ItemId },
        ComputerMoney: function () {
            model.modelData.BXZJE = 0;
            $(model.JFBXItemList).each(function (i, val) {
                model.modelData.BXZJE = parseFloat(model.modelData.BXZJE) + parseFloat(val.BXJE);
            })
        },
        DelItem: function (item) { //删除经费报销
            model.JFBXItemList.remove(item);
            var Ids = model.modelData.ItemIds.split(',');
            ItemId = "";
            $(Ids).each(function (i, val) {
                if (val != item.ID) {
                    ItemId = val + ",";
                }
            })
            ItemId = ItemId.substring(0, ItemId.length - 1);
            model.modelData.ItemIds = ItemId;
            model.ComputerMoney();

        }
    });
    function getdata() {
        var modelValue = JSON.stringify(model.modelData.$model);
        return { Action: "ADDJFBX", P1: modelValue };
    }
    function getSPdata(reason, status) {
        return { Action: "SPJFBX", P1: strId, P2: reason, spstatus: status };
    }

    avalon.ready(function () {

        if (strId != null) {
            //编辑加载数据
            $.getJSON('/API/FTAPI.ashx?Action=GETJFBXMODEL', { P1: strId }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    model.modelData = resultData.Result;
                    model.JFBXItemList = resultData.Result1;
                }
            })
            if (ComFunJS.getCookie('username') != JFBX.modelData.CRUser) {
                $(".btn-danger").remove();
            }
        }
        if (model.modelData.ItemIds != null) {
            //获取要报销的经费列表
            $.getJSON('/API/FTAPI.ashx?Action=GETJFBXITEMBYIDS', { P1: model.modelData.ItemIds }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    model.JFBXItemList = resultData.Result;
                    model.modelData.BXZJE = resultData.Result1;
                    model.modelData.ItemIds = resultData.Result2;
                }
            })
        }
    })
    $(function () {
        if (strId == null) {
            $(".btnSucc").text("送审");
        }

    })
</script>
